package com.atguigu.netty.buffer;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;

public class NettyByteBuf01 {
    public static void main(String[] args) {
        //创建一个ByteBuf
        //1.创建一个对象，该对象包含一个数组arr,是一个byte[10]
        //2.在netty的buffer中不需要flip进行反转
        //底层维护了一个readIndex和writeIndex
        //3.通过readIndex、writeIndex和capacity，将buffer分成了三个区
        //0 - readIndex 已经读取的区域
        //readIndex - writeIndex 可读区域
        //writeIndex - capacity 已经写入的区域

        ByteBuf buffer = Unpooled.buffer(10);
        for (int i = 0; i < 10; i++) {
            buffer.writeByte(i);
        }
        System.out.println("capacity = "+buffer.capacity());
        //输出
//        for (int i = 0; i < buffer.capacity(); i++) {
//            System.out.println(buffer.getByte(i));
//        }
        for (int i = 0; i < buffer.capacity(); i++) {
            System.out.println(buffer.readByte());
        }
    }
}
